//
//  ExchangeViewController.swift
//  UI
//
//  Created by admin on 14/9/18.
//  Copyright (c) 2014年 sinosun. All rights reserved.
//

import UIKit

class ExchangeViewController: UIViewController {


    @IBOutlet var back: UIImageView!

    @IBOutlet var font: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.title = "交换"
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "交换", style: UIBarButtonItemStyle.Bordered, target: self, action: "swap")
        
        self.back.alpha = 0.0
        //缩放比例
        self.back.transform = CGAffineTransformMakeScale(0.25, 0.25)
    }
    
    
    func swap(){
    
        var font = self.view.subviews[1] as UIImageView
        var back = self.view.subviews[0] as UIImageView
        self.navigationItem.rightBarButtonItem = nil
        UIView.beginAnimations("exchange", context: nil)
        //Curve 曲线
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)
        UIView.setAnimationDuration(1.0)
        
        font.alpha = 0.0
        back.alpha = 1.0
        font.transform = CGAffineTransformMakeScale(0.25, 0.25)
        back.transform = CGAffineTransformIdentity
        
        
        self.view.exchangeSubviewAtIndex(1, withSubviewAtIndex: 0)
        
        UIView.setAnimationDelegate(self)
        UIView.setAnimationDidStopSelector("animationFinished")
        UIView.commitAnimations()
        
    }
    
    func animationFinished(){
        println("-----------")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "交换", style: UIBarButtonItemStyle.Bordered, target: self, action: "swap")
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
